/**
 * @param {number[][]} matrix
 * @return {void} Do not return anything, modify matrix in-place instead.
 */
var rotate = function(matrix) {
  // 1.上下交换
  for(let i = 0; i < matrix.length / 2; i++) {
    for(let j = 0; j < matrix.length; j++) {
      let temp = matrix[i][j];
      matrix[i][j] = matrix[(matrix.length - i - 1)][j];
      matrix[(matrix.length - i - 1)][j] = temp;
    }
  }
  // 2.对角交换
  for(let i = 0; i < matrix.length; i++) {
    for(let j = 0; j <= i; j++) {
      let temp = matrix[i][j];
      matrix[i][j] = matrix[j][i];
      matrix[j][i] = temp;
    }
  }
  return matrix;
};
let matrix = [[1,2,3],[4,5,6],[7,8,9]];
console.log(rotate(matrix));
matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]];
console.log(rotate(matrix));
